package com.spica.platform.base.encrypt.encryptbody.exception;

import com.spica.platform.base.exception.errorcode.IErrorCode;
import com.spica.platform.common.utils.StringUtil;

import java.util.Arrays;

public enum EncryptRtnCodEnum implements IErrorCode {
    UN_KNOWN_ENCRYPT_ERROR("BASE_ENCRYPT_00000", "未知加密异常"),
    ENHANCE_ENCRYPT_UNDEFINED_ERROR("BASE_ENCRYPT_00001", "Encryption method is not defined. (加密方式未定义)"),
    ENHANCE_ENCRYPT_ERROR("BASE_ENCRYPT_00002", "Encrypted data failed. (加密数据失败)"),
    ;
    private String rtnCod;
    private String rtnMsg;

    EncryptRtnCodEnum(String rtnCod, String rtnMsg) {
        this.rtnCod = rtnCod;
        this.rtnMsg = rtnMsg;
    };
    @Override
    public String getRtnMessage() {
        return rtnMsg;
    }

    @Override
    public String getRtnCode() {
        return rtnCod;
    }

    @Override
    public IErrorCode getInstanceByErrorCode(String rtnCod) {
        return Arrays.stream(EncryptRtnCodEnum.values())
                .filter(encryptRtnCodEnum -> StringUtil.equals(encryptRtnCodEnum.rtnCod, rtnCod))
                .findFirst().orElse(EncryptRtnCodEnum.UN_KNOWN_ENCRYPT_ERROR);
    }
}
